package com.panshi.controller;

import com.panshi.service.AnswerService;
import com.panshi.util.CommonResult;
import com.panshi.vo.AnswerVO;
import com.panshi.vo.PageSizeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
@CrossOrigin
public class AnswerController {

    @Autowired
    private AnswerService answerService;

    @PostMapping("/ansQu")
    public List<List<AnswerVO>> findAnsQuery(@RequestBody PageSizeVO pageSizeVO){

        log.info("查询回答{}",answerService.findAnsQuery(pageSizeVO));
        pageSizeVO.setStartIndex(pageSizeVO.getStartIndexInfo());

        List<AnswerVO> ansQuery = answerService.findAnsQuery(pageSizeVO);
        List<AnswerVO> assQuery = answerService.findAssQuery(pageSizeVO);
        List<List<AnswerVO>> list = new ArrayList<>();
        list.add(ansQuery);
        list.add(assQuery);
        return list;
    }

    @GetMapping("/ansDe/{anid}")
    public CommonResult<String> deleteAns(@PathVariable int anid) {
        log.info("删除问题");
        answerService.deleteAns(anid);
        return new CommonResult<String>();
    }


    @GetMapping("/answer/{aaid}")
    public CommonResult<String> updateanswerNo(@PathVariable int aaid) {
        log.info("删除问题");
        answerService.updateanswerNo(aaid);
        return new CommonResult<String>();
    }

}
